﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AD.Model;
using AD.BLL;

public partial class Manager_User_PageData_CustomReport : WebManagerForm
{
    public IList<AccountFlowMod> Accounts = new List<AccountFlowMod>();
    public int currPageIndex = 1;
    public int MaxSize = 0;
    public int MaxPage = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        string indexstr = Request.QueryString["pageIndex"];
        string action = Request.QueryString["action"];
        string idstrs = Request.Params["ids"];
        string idstr = Request.Params["id"];
        if (!string.IsNullOrEmpty(action))
        {
            bool effect = int.TryParse(indexstr, out currPageIndex);

            if (action.Equals("gopage") && effect == true)
            {
                SetDataBind(UtilHepler.PAGE_SIZE, currPageIndex);
            }
            else if (action.Equals("delete") && effect == true)
            {
                int id;
                if (int.TryParse(idstrs, out id))
                    AccountFlowBLL.Delete(id);
                SetDataBind(UtilHepler.PAGE_SIZE, currPageIndex);
            }
            else if (action.Equals("deleteAll") && !string.IsNullOrEmpty(idstrs))
            {
                List<int> ids = GetIdToList(idstrs);
                foreach (var id in ids)
                {
                    AccountFlowBLL.Delete(id);
                }
                SetDataBind(UtilHepler.PAGE_SIZE, 1);
            }
        }
    }

    void SetDataBind(int pageSize, int index)
    {
        IList<AccountFlowMod> tmp = AccountFlowBLL.QueryByPage("", pageSize, index == 0 ? 0 : index - 1, out MaxSize);
        MaxPage = MaxSize / UtilHepler.PAGE_SIZE;
        if (MaxSize % UtilHepler.PAGE_SIZE != 0)
            MaxPage += 1;
        if (tmp != null)
        {
            Accounts = tmp;
            foreach (AccountFlowMod account in Accounts)
            {
                try
                {
                    account.UserName = UserBLL.QueryById(account.UserId).Email;
                }
                catch { }
            }
        }
    }
}